<template>
  <!-- 底部 -->
  <div class="my-footer">
    <!-- 全选 -->
    <div class="custom-control custom-checkbox">
      <input type="checkbox" class="custom-control-input" id="footerCheck" v-model="allSelect">
      <label class="custom-control-label" for="footerCheck">全选</label>
    </div>
    <!-- 合计 -->
    <div>
      <span>合计:</span>
      <span class="price">¥ {{ total }}</span>
    </div>
    <!-- 按钮 -->
    <Button type="info">结算 ( {{ account }} )</Button>
  </div>
</template>

<script>
export default {
    name:'MyFooter',
    data(){
        return {
            total:0,
            account:0
        }
    },
  props:['list'],
  watch:{
      list:{
          deep:true,
          handler(list){
              this.total=0;
               this.account=0;
              list.forEach(item=>{
                  if(item.goods_state){
                      this.total+=item.goods_price * item.goods_count;
                      this.account++
                  }
              })
            //   list.reduce((sum,item)=>{
            //       if(item.goods_state===true){
            //          sum+item.goods_price * item.goods_count;
            //         this.account++
            //       }
            //   },0)
          }
      }
  },
  computed:{
      allSelect:{
          set(selected){
            this.$emit('allSelect',selected)
          },
          get(){
              return this.list.every(item=>item.goods_state===true)
          }
      }
  }
}
</script>

<style lang="less" scoped>
.my-footer {
  position: fixed;
  z-index: 2;
  bottom: 0;
  width: 80%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background: #fff;

  .price {
    color: red;
    font-weight: bold;
    font-size: 15px;
  }
  .footer-btn {
    min-width: 80px;
    height: 30px;
    line-height: 30px;
    border-radius: 25px;
    padding: 0;
  }
}
</style>